﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Rose.Models;

namespace Rose.Helper
{
    public class CheckRelationHelpModel
    {
        private Database_RoseEntities db = new Database_RoseEntities();

        public bool IsFriendRelation(string selfId, string friendId)
        {
            return db.FriendRelations.Where(c => c.UserId == selfId && c.FriendId == friendId).Count() > 0 ? true : false;
        }

        public bool IsFocusRelation(string selfId, string friendId)
        {
            return db.FocusRelations.Where(c => c.UserId == selfId && c.FocusId == friendId).Count() > 0 ? true : false;
        }

        public int GetRequestType(string requestId)
        {
            RequestFriend model = db.RequestFriends.Where(c => c.Id == new Guid(requestId)).FirstOrDefault();
            if (model == null)
                return -1;
            if (model.IsResponsed==false) return 1;
            if (model.IsAccepted==false) return 2;
            return 3;
            // -1  出错
            // 1 no
            // 2  is not accept
            // 3  is accept

        }

        public bool IsLoverRelation(string selfId, string friendId)
        {
            return (db.LoverRelations.Where(c => c.ManId == selfId && c.WomanId == friendId).Count() > 0 ? true : false)
                || (db.LoverRelations.Where(c => c.ManId == friendId && c.WomanId == selfId).Count() > 0 ? true : false);
        }

        public bool HasLover(string selfId)
        {
            return db.UserInfos.Where(c => c.Id == selfId).First().HasLover;
        }

        public string GetLastLoverId(string selfId)
        {
            string loverId = new CheckHelpModel().CheckUserInfo(selfId).LoverId;
            return loverId;
        }

    }
}